package com.parkinglot.biz;

import com.parkinglot.dao.AdvertRecordDao;
import com.parkinglot.util.DatesUtil;
import com.parkinglot.vo.AdvertClickRateStatisticsVo;
import com.parkinglot.vo.IncomeStatisticsVo;
import com.parkinglot.vo.SelectAdvertByTimeVo;
import com.parkinglot.vo.SelectIncomeByTimeVo;
import lombok.Data;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Component
public class AdvertClickRateStatistics extends Statistics {
    @Resource
    AdvertRecordDao advertRecordDao;
    @Override
    protected void statistics(StatisticsContext context) {
        LinkedHashMap<String, Long> map = new LinkedHashMap();
        for (String hours : DatesUtil.hours) {
            map.put(hours, 0L);
        }
        List<SelectAdvertByTimeVo> adverts = advertRecordDao.selectAdvertByTime(context);
        for (SelectAdvertByTimeVo vo : adverts) {
            map.put(vo.getHours(), vo.getCount());
        }
        List<String> nameList = new ArrayList<>(25);
        List<Long> valueList = new ArrayList<>(25);

        for(Map.Entry<String, Long> entry : map.entrySet()){
            nameList.add(entry.getKey());
            valueList.add(entry.getValue());
        }
        context.setResult(new AdvertClickRateStatisticsVo(nameList,valueList));
    }
}
